how to insert multiple characters into a string in C [closed]

Posted by John Li on Programmers See other posts from Programmers or by John Li
Published on 2012-10-05T03:14:34Z Indexed on 2012/10/05 3:50 UTC
Read the original article Hit count: 175

Filed under:
|

I wish to insert some characters into a string in C: Example: char string[20] = "20120910T090000";

I want to make it something like "2012-09-10-T-0900-00"

My code so far:

void append(char subject[],char insert[], int pos) {

char buf[100]; 

strncpy(buf, subject, pos); 

int len = strlen(buf);

strcpy(buf+len, insert); 

len += strlen(insert);  

strcpy(buf+len, subject+pos); 

strcpy(subject, buf);   

}

When I call this the first time I get: 2012-0910T090000

However when I call it a second time I get: 2012-0910T090000-10T090000

Any help is appreciated

© Programmers or respective owner

Related posts about c

    Related posts about strings